//
//  main.m
//  Hiranipra.Game.Server
//
//  Created by Ben Vanik on 5/30/08.
//  Copyright __MyCompanyName__ 2008. All rights reserved.
//

#include "HiranipraCommon.h"
#include "ServerApp.h"
#include "CoreFoundation/CoreFoundation.h"

using namespace Hiranipra;
using namespace Hiranipra::Server;

ServerApp _serverApp;

int main(int argc, char *argv[])
{
    CFBundleRef bundle = CFBundleGetMainBundle();
    CFURLRef url = CFBundleCopyBundleURL( bundle );
    UInt8 urlBuffer[ 1024 ];
    CFURLGetFileSystemRepresentation( url, true, urlBuffer, 1024 );
    CFRelease( url );
    CFRelease( bundle );
    wstring appPath = wstring( WidenString( ( char* )urlBuffer ) );
	int slash = appPath.find_last_of( L"/" );
	if( slash <= 0 )
		slash = appPath.find_last_of( L"\\" );
	appPath = appPath.substr( 0, slash + 1 );
    
	vector<wstring> args;
	for( int n = 1; n < argc; n++ )
		args.push_back( wstring( WidenString( argv[ n ] ) ) );
	
	_serverApp.RegisterAssembly( L"Hiranipra.Platform.PhysFS.bundle" );
	_serverApp.RegisterAssembly( L"Hiranipra.Platform.Windows.bundle" );
    
	return _serverApp.Start( appPath, args );
}
